<?php
ob_start();
include '/var/www/html/new/d/common/header.html';
include '/var/www/html/new/d/common/left.html';
include '/var/www/html/new/d/common/autoload.php';
include '/var/www/html/new/d/common/Prod_Common.php';
$out_html = ob_get_contents();
ob_end_clean();
$sid = $_SESSION['sid'];
$prods = array();

// 身份验证
if(!in_array($_SESSION['sdtype'], array(0,2,3,6,9)) && !isset($_REQUEST['action'])) exit('身份不合法');

if($_SESSION['sdtype']==2){// 直接资源方
	$sql = "select apply_did from uu_land where salerid=".$_SESSION['saccount']." limit 1";
	$GLOBALS['le']->query($sql);
	if(!$GLOBALS['le']->fetch_assoc()) exit('{"status":"fail","msg":"身份不合法"}');
	$sid = $s_sid = $GLOBALS['le']->f('apply_did');
}

if(($_SESSION['sdtype']==2 || $_SESSION['sdtype']==3) && $_REQUEST['action']=='queryproduct'){// 直接资源方
    if($_SESSION['sdtype']==3){//合并过的终端并且是主体
        $sql = "select preSalerID from pft_terminal_share where nowSalerID={$_SESSION['saccount']}";
        $GLOBALS['le']->query($sql);
        while($row=$GLOBALS['le']->fetch_assoc()){
            $total_salerid .= $row['preSalerID'].',';
        }
        $total_salerid = rtrim($total_salerid,',');
    }else{
        $total_salerid = $_SESSION['account'];
    }
    $sql = "select id,imgpath,p_type,terminal,title,salerid from uu_land where salerid in ($total_salerid)";
    $GLOBALS['le']->query($sql);
    while($row=$GLOBALS['le']->fetch_assoc()){
        $prods[] = $row;
    }
    exit(json_encode(array('status'=>'success','list'=>$prods)));
}
		
		
// 获取产品
$fuzzy = '';
if($sid!=1) {
    $where1 = "apply_did=$sid and ";
    $where2 = " and id IN (SELECT contact_id FROM uu_products WHERE apply_did=$sid)";
    //去掉没有票类的产品(待发布的产品)
}
if(($_GET['sid']+0)>0) $where1 = "id={$_GET['sid']} and ";
if($s_sid) $where1.= "salerid='".$_SESSION['saccount']."' and ";
//没用的景区
$where1 .= '  id not in (7288) and ';
if($_REQUEST['keyword']!='') $fuzzy = "and title like '%".trim($_REQUEST['keyword'])."%'";
$sql = "select title,salerid,terminal,imgpath,id,p_type from uu_land where $where1 status<3 and p_type<>'F' $fuzzy $where2 order by p_type asc ";


$GLOBALS['le']->query($sql);
$prods = array();
while($r = $GLOBALS['le']->fetch_assoc()) {
	$prods[] = $r;
}

// 异步获取搜索产品
if(isset($_REQUEST['action']) && $_REQUEST['action']=='queryproduct'){
	if(!($sid = $_SESSION['sid'])) exit('{"status":"fail","msg":"登录超时","code":0}');
	if(!in_array($_SESSION['sdtype'], array(0,2,6,9))) exit('{"status":"fail","msg":"身份不合法"}');
	exit(json_encode(array('status'=>'success','list'=>$prods)));
	exit;
}





$var['prods'] = $prods;// 产品信息
$var['canmod'] = 1;
if($_SESSION['sid']==36188) $var['canmod'] = 0;

echo $out_html;
include '/var/www/html/new/d/tpl/terminal.html';
include '/var/www/html/new/d/common/footer.html';
?>